import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import vueSetupExtend from "vite-plugin-vue-setup-extend";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), "./src/assets/icons")],
      symbolId: "icon-[name]",
    }),
    AutoImport({
      imports: ["vue", "vue-router"],
      // 解决eslint报错问题
      eslintrc: {
        enabled: true,
      },
    }),
    Components({
      // 指定组件位置，默认是src/components
      dirs: ["src/components"],
      // ui库解析器
      // resolvers: [ElementPlusResolver()],
      extensions: ["vue"],
      // 配置文件生成位置
      dts: "components.d.ts",
    }),
    vueSetupExtend(),
  ],

  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "src"),
      },
    ],
  },
  css: {
    preprocessorOptions: {
      //define global scss variable
      scss: {
        additionalData: `@import '@/style/var.scss';`,
      },
    },
  },
});
